<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增文件信息配置')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fileconf-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">业务类型：</label>
                <div class="col-sm-8">
                    <input name="bizeType" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文件类型：</label>
                <div class="col-sm-8">
                    <select name="fileTypeLimit" id = "fileTypeLimit" class="form-control noselect2 selectpicker" data-none-selected-text="请选择文件类型" multiple th:with="type=${@dict.getType('file_type')}">
                        <option th:each="dict:${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">文件大小(kb)：</label>
                <div class="col-sm-8">
                    <input name="fileSizeLimit" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">存储文件夹名称：</label>
                <div class="col-sm-8">
                    <input name="path" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input name="description" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否可用：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" checked>
                        <span></span>
                    </label>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script type="text/javascript">
        var prefix = ctx + "file/fileconf"
        $("#form-fileconf-add").validate({
            rules:{
                fileSizeLimit:{
                    number:true,
                    min:0
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-fileconf-add").serializeArray();
                var enabled = $("input[id='status']").is(':checked') == true ? 1 : 0;
                var fileTypeLimit = $("select[id='fileTypeLimit']").val();
                if(fileTypeLimit==null){
                    data.push({"name": "fileTypeLimit", "value": ""});
                }
                data.push({"name": "enabled", "value": enabled});
                $.operate.save(prefix + "/add", data);
            }
        }
    </script>
</body>
</html>